package org.bite.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.bite.model.userInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/response")
//返回数据 等于@Controller + @ResponseBody
//@RestController

//返回视图 类注解也是方法注解

@Controller

//配合@Controller 等于 @RestController
//@ResponseBody

public class ResponseController {
    @RequestMapping("/View")
    public String getView(){
        return "/index.html";//找绝对路径 /index.html
    }

    @RequestMapping("/View2")
    public String getView2(){
        return "index.html";//找相对路径 文件夹下的/response/index.html
    }

    @RequestMapping("/getUserInfo")
    @ResponseBody
    public userInfo getJson(){
        return new userInfo("xh",12,"1234");
    }

    //设置状态码

    @RequestMapping("/setStatus")
    @ResponseBody
    public String setStatus(HttpServletResponse response){
        response.setStatus(404);
        return "设置404成功";
    }
}
